import { request } from "./request"


// 获取学生信息
export const studentList = () => {
	return request({
		url: 'v1/parents/studentList',
		method: 'GET',
	})
}

// 获取当前用户信息
export const getMemberInfo = () => {
	return request({
		url: 'v1/members/getMemberInfo',
		method: 'GET',
	})
}

// 获取孩子手机状态 获取孩子手机状态:1.管控状态 2.剩余电量 3.锁屏状态 4.在线状态 (家长端)
export const getStudentStatus = (data: {studentId:string | number}) => {
	return request({
		url: 'v1/deviceStatus/getStudentStatus',
		method: 'GET',
		data
	})
}

// 应用使用时长统计使用统计 type: 统计方式(1-按日期统计, 2-统计本周, 3-统计上周) date: 	统计日期(格式为yyyy-MM-dd)
export const statistics = (data: {studentId:string | number, type: 1 | 2 | 3, date ?: string}) => {
	return request({
		url: 'v1/appRecords/statistics',
		method: 'GET',
		data:{
			...data,
			date: recordDateTime()
		}
	})
}


// 获取banner图 

export const getBannerImage = () => {
	return request({
		url: 'v1/bannerImage/getBannerImage',
		method: 'GET',
		data: {
			appType: '1'
		}
	})
}



// *************************  9.应用游戏管理 *************************/

// 获取游戏应用列表
export const general = async ({studentId}) => {
	return request({
		url: 'v1/applicationPrograms/general',
		method: 'GET',
		data: {
			studentId
		}
	})
}

// 设置禁用
export const disabledApp = async ({id}) => {
	return request({
		url: 'v1/apps/updateApp',
		method: 'POST',
		data: {
			holidayStatus:"2",
			dailyStatus:"1",
			id
		}
	})
}


// 设置不不限制
export const updateAppNoDisabled = async ({id}) => {
	return request({
		url: 'v1/apps/updateApp',
		method: 'POST',
		data: {
			holidayStatus:"2",
			dailyStatus:"2",
			dailyStartTime:"00:00",
			dailyEndTime: "00:00",
			id
		}
	})
}
// 限时使用
export const limitUseTime = async ({dailyStartTime, dailyEndTime, id}) => {
	return request({
		url: 'v1/apps/updateApp',
		method: 'POST',
		data: {
			holidayStatus:"2",
			dailyStatus:"3",
			dailyStartTime,
			dailyEndTime,
			id
		}
	})
}


// *************************  11.小程序管理 *************************/


// 获取微信小程序列表 (家长端)
interface smallProgramListProps{
	studentId: string | number
	channel?: string | number
	versionCode?: string | number
}
export const smallProgramList = async (data: smallProgramListProps) => {
	return request({
		url: `v1/smallProgramStudent/smallProgramList?studentId=${data.studentId}&channel=parent_yingyongbao&versionCode=31`,
		method: 'GET',
		data
	})
}

// 获取QQ小程序列表 (家长端) 
interface smallProgramListQQProps{
	studentId: string | number
}
export const smallProgramListQQ = async (data: smallProgramListQQProps) => {
	return request({
		url: `v1/smallProgramStudent/smallProgramListQQ`,
		method: 'GET',
		data
	})
}

/// 修改小程序状态 (家长端)
interface updateSmallProgramStatusProps{
		id: string | number
		smallProgramId: string | number
		useStatus: "1" | "2" // 	使用状态【1-禁用，2-不限时，3-限制时间段】	
		startTime?: string
		endTime?: string,
}
export const updateSmallProgramStatus = async (data:updateSmallProgramStatusProps) => {
	return request({
		url: 'v1/smallProgramStudent/updateSmallProgramStatus',
		method: 'POST',
		data
	})
}


// *************************  12.孩子图标隐藏 *************************/

// 获取当前状态
interface getStudentIconStatusProps{
	studentId: number | string
}
export const getStudentIconStatus = async (data: getStudentIconStatusProps) => {
	return request({
		url: 'v1/parents/getStudentIconStatus',
		method: 'GET',
		data
	})
}
// 修改开启或者关闭
interface updateStudentIconStatusProps{
	studentId: string | number
	subIconSwitch: 1 | 2 // 图标状态(1:显示,2:隐藏)
}
export const updateStudentIconStatus = async (data:updateStudentIconStatusProps) => {
	return request({
		url: 'v1/parents/updateStudentIconStatus',
		method: 'POST',
		data
	})
}




// *************************  13.应用时长统计 *************************/

// 应用使用时长统计使用统计
interface appRecordsStatisticsProps{
	studentId: string | number
	type: 1 | 2 | 3, // 统计方式(1-按日期统计, 2-统计本周, 3-统计上周)
	date?: string // 统计日期(格式为yyyy-MM-dd)
}
export const appRecordsStatistics = async (data: appRecordsStatisticsProps) => {
	return request({
		url: 'v1/appRecords/statistics',
		method: 'GET',
		data
	})
}



// *************************  14.临时解绑 *************************/

//  获取临时解绑
export const getTemporaryUnBindInfo = async ({ studentId }: {studentId: string | number}) => {
	return request({
		url: 'v1/parents/getTemporaryUnBindInfo',
		method: 'GET',
		data: {
			studentId
		}
	})
}

// 提交临时解绑
interface temporaryUnBindProps{
	studentId: string | number
	startTime: string
	endTime: string
}
export const temporaryUnBind = async (data:temporaryUnBindProps) => {
	return request({
		url: 'v1/parents/temporaryUnBind',
		method: 'POST',
		data
	})
}
// 删除临时解绑
export const finishTemporaryUnBind = async ({ studentId }: {studentId: string | number}) => {
	return request({
		url: 'v1/parents/finishTemporaryUnBind',
		method: 'GET',
		data: {
			studentId
		}
	})
}




// *************************  15.新安装的应用 *************************/
// 获取新安装的应用
interface newAppsProps{
	page: number
	size: number
	studentId: string | number
	sort?: string | number
}
export const newApps = async (data: newAppsProps) => {
	return request({
		url: 'v1/apps/new-apps',
		method: 'GET',
		data
	})
}
interface OnOffAppProps{
	appId: string | number
	status: 'ON' | 'OFF', // ON-启用,OFF-禁用
	studentId: string | number
}
// 禁用/同意安装APP
export const onOffApp = async (data: OnOffAppProps) => {
	return request({
		url: 'v1/apps/on-off-app',
		method: 'POST',
		data
	})
}


// *************************  16.应用白名单 *************************/


// 用户APP白名单（学生端）
export const studentWhitelist= async () => {
	return request({
		url: 'v1/appWhitelist/studentWhitelist',
		method: 'GET',
		data:{
			page:1,
			size: 100
		}
	})
}

// 获取白名单
interface parentWhitelistProps{
	page: number
	size: number
	studentId: string | number
	sort?: string | number
}
export const parentWhitelist = async (data: parentWhitelistProps) => {
	return request({
		url: 'v1/appWhitelist/parentWhitelist',
		method: 'GET',
		data
	})
}

// 添加白名单
interface appWhitelistAddProps{
	studentId: string | number
	appName: string
	id: string | number
	packageName: string
}
export const appWhitelistAdd = async (data:appWhitelistAddProps) => {
	return request({
		url: 'v1/appWhitelist/add',
		method: 'POST',
		data
	})
}

// 移除白名单
interface appWhitelistDeleteProps{
	[key: string]: string
}
export const appWhitelistDelete = async (data:appWhitelistDeleteProps) => {
	return request({
		url: 'v1/appWhitelist/delete',
		method: 'POST',
		data
	})
}


// 更新白名单可使用时长(家长端)
export const updateUseTimeInt = async (data) => {
	return request({
		url: 'v1/appWhitelist/updateUseTimeInt',
		method:'POST',
		data
	})
}





// *************************  10.使用时间管理 *************************/

// 查询时间段管控是否生效,每日可用时长 V2(家长端)
export const queryControlSwitchAndAvailableTime = async ({studentId}) => {
	return request({
		url: 'v2/patternParents/queryControlSwitchAndAvailableTime',
		method:'POST',
		data: {
			studentId
		}
	})
}


// 设置日常或周末可用时长 V2(亲情时刻守护家长家长端)
export const settingAvailableTime = async ({studentId, weekendAvailableTime, dailyAvailableTime, type = 1, dailyAvailableTimeName, weekendAvailableTimeName}) => {
	return request({
		url: 'v2/patternParents/settingAvailableTime',
		method:'POST',
		data: {
			studentId,
			weekendAvailableTime, 
			dailyAvailableTime, 
			type, 
			dailyAvailableTimeName,
			weekendAvailableTimeName
		}
	})
}

// 查询周一到周日禁用时间段
export const patternParentsQuery= async ({studentId, type = 1}) => {
	return request({
		url: 'v2/patternParents/query',
		method: 'GET',
		data:{
			studentId,
			type: 1
		}
	})
}
// 设置禁用时间段
interface patternParentsSettingProps{
	patternParentSlots: Array<{
		dayTheWeek?: number,
		patternTimeScopes?: Array<{
			startTime: string,
			endTime: string
		}>
	}>,
	studentId: string | number
	type: 1
}
export const patternParentsSetting = async (data: patternParentsSettingProps) => {
	return request({
		url: 'v2/patternParents/setting',
		method:'POST',
		data
	})
}

// 开启和关闭设置每日可用时间
interface settingSwitchProps{
	dailySettingSwitch: number
	studentId: string | number
	type: 1
	weekendSettingSwitch: string  | number
}
export const settingSwitch = async (data: settingSwitchProps) => {
	return request({
		url: 'v2/patternParents/settingSwitch',
		method:'POST',
		data
	})
}



const recordDateTime = () => {
	const d = new Date();
	return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`
}

//根据日期查询APP使用统计应用使用详情
export const appUseRecordList = async ({studentId, recordDate = recordDateTime()}) => {
	return request({
		url: 'v1/appUseRecords/app-use-record-list',
		method:'GET',
		data: {
			studentId,
			// recordDate
		}
	})
}




// *************************  7.定位 *************************/

// 获取定位 
export const findLocation = async ({studentId}) => {
	return request({
		url: 'v1/parents/findLocation',
		method:'POST',
		data: {
			studentId
		}
	})
}

// 轨迹聚集记录查询
interface findGatherRecordsProps{
	studentId: string
	recordDate: string
}
export const findGatherRecords = async ({studentId, recordDate}: findGatherRecordsProps) => {
	return request({
		url: 'v1/traceGatherRecords/findGatherRecords',
		method:'GET',
		data: {
			studentId,
			// recordDate
		}
	})
}

// 获取区域设置列表
interface traceScopesRecordProps{
	studentId: string | number
	page: number,
	size: number
	sort?: any
}
export const traceScopesRecord = async (data: traceScopesRecordProps) => {
	return request({
		url: 'v2/traceScopes/record',
		method:'GET',
		data: {
			...data,
			versionCode: 33,
			channel: 'daili_xhs_xu_0023'
		}
	})
}

// 设置围栏
interface traceScopesAddProps{
	studentId: string | number
	address: string
	name: string
	latitude: number
	longitude: number
	warnDistance: string
	startTime: string
	endTime: string
}

export const traceScopesAdd = async (data: traceScopesAddProps) => {
	return request({
		url: 'v2/traceScopes/add',
		method:'POST',
		data
	})
}


//   安全区域
export const traceScopesScope = async ({studentId}: {studentId: number | string}) => {
	return request({
		url: 'v2/traceScopes/scope',
		method:'GET',
		data: {
			studentId
		}
	})
}

// 修改
export const traceScopesUpdate = async (data) => {
	return request({
		url: 'v2/traceScopes/update',
		method:'POST',
		data
	})
}

// 删除
export const traceScopesDelete = async (data) => {
	return request({
		url: 'v2/traceScopes/delete',
		method:'POST',
		data
	})
}


// 获取分享码
export const remainMoneyAndSharecode = async () => {
	return request({
		url: "v1/payGain/remainMoneyAndSharecode",
		method: "GET"
	})
}





/** 分享页面的接口 */
export const  queryUserOview = ()=>{
	return request({
		url: "v1/recommend/userOverview",
		method: "GET"
	})
}

export const queryRewardDetails = () => {
	return request({
		url: "v1/recommend/rewardDetails",
		method: "GET"
	})
 }
 
  export const queryRanking = () => {
	  return request({
	  	url: "v1/recommend/ranking",
	  	method: "GET"
	  })
  }
  
  
export const queryGetRecommendInfo = (data:any) => {
   return request({
	url: "v1/recommend/getRecommendInfo",
	method: "POST",
	data
   })
}

 export const sendAccessStatistics = () =>{
	 return request({
	 	url: "v1/studentDownload/shareStatistics",
	 	method: "GET",
	 })
 }
 
  export const encodeURIComponent = (data:any)=> {
	  return request({
	  	url: "v1/miniappSignature/getSignature",
	  	method: "POST",
	  	data
	  })
 }
 
 // 发送推送(家长实时查询孩子位置) (家长端)
 export const pushToStudent = ({studentId}) =>{
 	 return request({
 	 	url: "v1/parents/pushToStudent",
 	 	method: "GET",
		data: {
			studentId
		}
 	 })
 }